#include "GameEntity.h"
# include <iostream>
GameEntity::GameEntity(World* w, int x, int y)
{
	w->add(this);
	shader = NULL;
	image = NULL;

	xPos = x;
	yPos = y;

	xVel = 0;
	yVel = 0;

}

GameEntity::GameEntity(World* w, int x, int y, Image* i)
{
	w->add(this);
	shader = NULL;

	image = i;
	xPos = x;
	yPos = y;

	xVel = 0;
	yVel = 0;

	angle = 0;

	width = i->getWidth();
	height = i->getHeight();
}

GameEntity::~GameEntity(void)
{
}




void GameEntity::update()
{
	xVel = 0;
	yVel = 0;

}

void GameEntity::move(float xV, float yV)
{
	xVel += xV;
	yVel += yV;
}


void GameEntity::commitMovement()
{
	xPos+=xVel;
	yPos+=yVel;
}




void GameEntity::render(float interpolation, int xOffset, int yOffset)
{
	if(image != NULL)
	{
		if(rectanglesOverlap(xPos, yPos, image->getWidth(), image->getHeight(), -xOffset, -yOffset, 2000,2000)) //ensure entity is only rendered when it is on screen.
		{
			glEnable(GL_BLEND);
			glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 

			image->draw(xPos + xVel*interpolation + xOffset - xVel, yPos + yVel*interpolation + yOffset - yVel, angle);
		}
	}
}

void GameEntity::setX(int x)
{
	xPos = x;
}

void GameEntity::setY(int y)
{
	yPos = y;
}

float GameEntity::getX()
{
	return xPos;
}

float GameEntity::getY()
{
	return yPos;
}

float GameEntity::getXVel()
{
	return xVel;
}

float GameEntity::getYVel()
{
	return yVel;
}


void GameEntity::setShader(Shader* s)
{
	shader = s;
}